package com.nineclock.system.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.mapper.SysCompanyUserMapper;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 处理导入员工数据的监听器
 */
public class ExcelMemberListener extends AnalysisEventListener<ExcelMember> {

    private List<ExcelMember> memberList = new ArrayList<>();

    private SysCompanyUserService companyUserService;

    public ExcelMemberListener(SysCompanyUserService companyUserService) {
        this.companyUserService = companyUserService;
    }

    @Override
    public void invoke(ExcelMember excelMember, AnalysisContext analysisContext) {
        // 每处理完一行数据，调用该方法
        memberList.add(excelMember);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        companyUserService.handleParsedData(memberList);
    }
}
